package com.hanamaki.ltd;

import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

public class AppiumTestNg {

    WebDriver driver;

    @BeforeMethod
    public void setUp() throws MalformedURLException {

        /* 编写配置 */
        DesiredCapabilities capabilities = new DesiredCapabilities();
        capabilities.setCapability("deviceName", "127.0.0.1:62001");
        capabilities.setCapability("platformName", "Android");
        capabilities.setCapability("appPackage", "com.iBookStar.activityOff");
        capabilities.setCapability("appActivity", "com.iBookStar.activityOff.Splash");

        URL url = new URL("http://localhost:4723/wd/hub");
        driver = new AndroidDriver<WebElement>(url,capabilities);

        /* 隐式等待 等待时间 */
        WebDriver.Timeouts timeouts = driver.manage().timeouts();
        timeouts.implicitlyWait(30, TimeUnit.SECONDS);


    }

    @Test
    public void test() {

        /* 点击开始 体验 */
        WebElement element = driver.findElement(By.id("com.iBookStar.activityOff:id/go"));
        element.click();
        /**/


    }

    @AfterMethod
    public void close() {
        driver.quit();
    }

}
